﻿#region << 版 本 注 释 >>

/*----------------------------------------------------------------
* 类 名 称 ：SafeARC
* 类 描 述 ：
* 作    者 ：henrychang
* 创建时间 ：2019/1/6 18:25:05
*******************************************************************
* Copyright @ henrychang 2019. All rights reserved.
*******************************************************************
//----------------------------------------------------------------*/

#endregion << 版 本 注 释 >>

using System.Collections.Generic;
using UnityEngine;

namespace TouchFish.RefCounter
{
    public sealed class SafeARC : IRefCounter
    {
        public int RefCount
        {
            get { return mOwners.Count; }
        }

        public HashSet<object> Owners
        {
            get { return mOwners; }
        }

        private readonly HashSet<object> mOwners = new HashSet<object>();

        public void Retain(object refOwner)
        {
            if (!Owners.Add(refOwner))
            {
                Debug.LogError("ObjectIsAlreadyRetainedByOwnerException");
            }
        }

        public void Release(object refOwner)
        {
            if (!Owners.Remove(refOwner))
            {
                Debug.LogError("ObjectIsNotRetainedByOwnerExceptionWithHint");
            }
        }
    }
}